#ifndef BSP_SPI_BUS_H__
#define BSP_SPI_BUS_H__

#include <stdint.h>
#include "spi_config.h"

#define SPI_BUFFER_SIZE (128)

typedef struct bsp_spi_bus
{
    uint8_t is_busy; /* SPI忙状态，0表示不忙，1表示忙 */
    uint8_t tx_buf[SPI_BUFFER_SIZE];
    uint8_t rx_buf[SPI_BUFFER_SIZE];
    uint32_t data_len;
    volatile uint32_t tx_state;
} spi_bus_inst_t;

extern volatile spi_bus_inst_t g_spi_ctrl[SPI_TOTAL_NUM];

void bsp_initSpiBus(uint8_t spi_num);
int16_t bsp_getSpiIndex(uint8_t spi_num);
void bsp_spiTransfer(uint8_t spi_num);
void bsp_spiBusEnter(uint8_t spi_num, uint8_t device_id);
void bsp_spiBusExit(uint8_t spi_num, uint8_t device_id);
uint8_t bsp_isSpiBusBusy(uint8_t spi_num);

#endif
